import 'package:intl/intl.dart';

String formatDateTime(DateTime dateTime) {
  final now = DateTime.now();
  final today = DateTime(now.year, now.month, now.day);
  final yesterday = today.subtract(const Duration(days: 1));

  if (dateTime.isAfter(today)) {
    // 今天
    return "今天 ${DateFormat('HH:mm').format(dateTime)}";
  } else if (dateTime.isAfter(yesterday)) {
    // 昨天
    return "昨天 ${DateFormat('HH:mm').format(dateTime)}";
  } else if (dateTime.year == now.year) {
    // 今年
    return DateFormat('MM/dd HH:mm').format(dateTime);
  } else {
    // 其他时间
    return DateFormat('yyyy/MM/dd HH:mm').format(dateTime);
  }
}

bool isSameDay(DateTime date1, DateTime date2) {
  return date1.year == date2.year &&
      date1.month == date2.month &&
      date1.day == date2.day;
}
